package com.lmx.repoDomain.tmodel;

import java.util.ArrayList;
import java.util.List;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.ForeignKey;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.Table;

import org.hibernate.annotations.Cache;
import org.hibernate.annotations.CacheConcurrencyStrategy;
import org.hibernate.annotations.Fetch;
import org.hibernate.annotations.FetchMode;
import org.hibernate.annotations.NotFound;
import org.hibernate.annotations.NotFoundAction;

import com.fasterxml.jackson.annotation.JsonBackReference;
import com.fasterxml.jackson.annotation.JsonManagedReference;

import io.katharsis.resource.annotations.JsonApiResource;
import io.katharsis.resource.annotations.JsonApiToMany;
import io.katharsis.resource.annotations.JsonApiToOne;

@JsonApiResource(type = "privilege")
@Table(name = "t_s_function")
@Entity
@Cache(usage = CacheConcurrencyStrategy.NONSTRICT_READ_WRITE)
public class Privilege extends BaseDataEntity {

	private static final long serialVersionUID = 1L;
	private String code;// 编码
	private String showName;// 权限名称
	private String mobileMenuName;// 菜单名称
	private String mobileIcon;// 菜单图标
	private Integer type;// 权限类型
	private Integer level;// 权限等级
	private String link;// 链接
	private String icon;// 图标
	private Integer order;// 权限顺序
	private Privilege parent; // 父权限
	private List<Privilege> children;
	private String remark;// 备注
	private Integer systemType;// 权限类型
	private Tenant tenant;// 对应租户

	public Privilege() {
	}

	@Column(name = "functioncode", length = 32)
	public String getCode() {
		return code;
	}

	public void setCode(String code) {
		this.code = code;
	}

	@JsonApiToOne
	@ManyToOne(fetch = FetchType.EAGER)
	@JoinColumn(name = "tenant_id", foreignKey = @ForeignKey(name = "null"))
	public Tenant getTenant() {
		return tenant;
	}

	public void setTenant(Tenant tenant) {
		this.tenant = tenant;
	}

	@Column(name = "functionname", length = 32)
	public String getShowName() {
		return showName;
	}

	public void setShowName(String showName) {
		this.showName = showName;
	}

	@Column(name = "mo_menuname", length = 32)
	public String getMobileMenuName() {
		return mobileMenuName;
	}

	public void setMobileMenuName(String mobileMenuName) {
		this.mobileMenuName = mobileMenuName;
	}

	@Column(name = "mo_menuicon", length = 32)
	public String getMobileIcon() {
		return mobileIcon;
	}

	public void setMobileIcon(String mobileIcon) {
		this.mobileIcon = mobileIcon;
	}

	@Column(name = "functiontype")
	public Integer getType() {
		return type;
	}

	public void setType(Integer type) {
		this.type = type;
	}

	@Column(name = "functionlevel")
	public Integer getLevel() {
		return level;
	}

	public void setLevel(Integer level) {
		this.level = level;
	}

	@Column(name = "link", length = 64)
	public String getLink() {
		return link;
	}

	public void setLink(String link) {
		this.link = link;
	}

	@Column(name = "iconfile", length = 32)
	public String getIcon() {
		return icon;
	}

	public void setIcon(String icon) {
		this.icon = icon;
	}

	@Column(name = "functionorder")
	public Integer getOrder() {
		return order;
	}

	public void setOrder(Integer order) {
		this.order = order;
	}

	@JsonApiToOne
	@ManyToOne
	@JoinColumn(name = "parentfunctionid", nullable = true, foreignKey = @ForeignKey(name = "null"))
	@NotFound(action = NotFoundAction.IGNORE)
	@JsonBackReference
	public Privilege getParent() {
		return parent;
	}

	public void setParent(Privilege parent) {
		this.parent = parent;
	}

	@JsonApiToMany
	@OneToMany(mappedBy = "parent")
	@Fetch(value = FetchMode.JOIN)
	@JsonManagedReference
	public List<Privilege> getChildren() {
		return children == null ? new ArrayList() : children;
	}

	public void setChildren(List<Privilege> children) {
		this.children = children;
	}

	@Column(name = "remark")
	public String getRemark() {
		return remark;
	}

	public void setRemark(String remark) {
		this.remark = remark;
	}

	@Column(name = "system_type")
	public Integer getSystemType() {
		return systemType;
	}

	public void setSystemType(Integer systemType) {
		this.systemType = systemType;
	}
}
